<template>
	<view class="invitelrview">
		<view class="abc">
      <view class="abced">
        <view class="h1">选择职位</view>
        <view class="pos">
          <block v-for="(item,index) in getCurPageList" :key="index">
            <view class="name" :class="{active:activeIndex===index}"
             @click="onSelectActiv(index)"
            >{{item.positionName}}</view>
          </block>
        </view>
      </view>
    </view>
    <view class="def">
      <view class="abced">
        <u-cell-group>
          <u-cell-item  title="选择面试时间" arrow
                        @click="onSelectTime"
          :icon-style="{
            width: '15rpx',
height: '29rpx'
          }"
                        :value="timeValue"
          />
        </u-cell-group>
      </view>

    </view>
    <u-button  hover-class="none" :custom-style="{
      marginTop:'695rpx',
      marginBottom:'342rpx',
      width: '442rpx',
  height: '84rpx',
  background: '#53B9B2',
  borderRadius: '30rpx',

  fontSize: '31rpx',
  fontFamily: 'PingFang SC',
  fontWeight: 500,
  color: '#FFFFFF'
    }" @click="onCompanyInviteDelivery">立即邀约</u-button>
    <u-picker
        mode="time"
        v-model="active.appointmentstart.show"
        :start-year="active.appointmentstart.startTime"
        :end-year="active.appointmentstart.endTime"
        :default-time="active.appointmentstart.appointmentDate"
        :params="active.appointmentstart.timeParams"
        @confirm="onappActiveStartDataChange"
    ></u-picker>
	</view>
</template>

<script>
import {companyPositionList,companyInviteDelivery} from '@/api/company'
import {selectTimeData as selectData,getTimeDate} from '@/utils/utils'
	export default {
		data() {
			return {
        timeValue:'',//时间选择
        activeIndex:-1,//是否要勾选
        positionId:'',//职位id
        resumeId:'',//简历id
        resumeName:'',//昵称
        details: {}, //数据
        active:{
          //预约
          appointmentstart:{
            ...selectData
          },
        }
			};
		},
    onLoad(opt){
      this.resumeId = opt.resumeId
      this.resumeName = opt.resumeName
      this.getTimeDates()
      this.companyPositionList()
    },
    methods:{
      //选择职位
      onSelectActiv(index){
        this.activeIndex = index===this.activeIndex?-1:index
        if(this.activeIndex>-1){
          this.positionId= this.getCurPageList[this.activeIndex].id
          this.details = {
            ...this.getCurPageList[this.activeIndex]
          }
        } else {
          this.positionId = ''
          this.details = {}
        }

      },
      onCompanyInviteDelivery(){
        if(!this.positionId.length){
          this.$showToast('请选择职位')
          return
        } if(!this.timeValue.length){
          this.$showToast('请选择面试时间')
          return
        }
        const data ={
          resumeId:this.resumeId,
          positionId:this.positionId,
          interviewTime:this.timeValue
        }
        uni.showModal({
          title: '提示',
          content: `是否邀请${this.resumeName}参加${this.details.positionName}职位进行面试?`,
          success: res=>{
            if (res.confirm) {
              this.companyInviteDelivery(data)
            } else if (res.cancel) {
              this.$showToast('已取消')
            }
          }
        });
      },
      //邀请查看简历
      companyInviteDelivery(data){
        this.$showLoading({
          title:'邀请中...'
        })
        companyInviteDelivery(data).then(res => {
          const {code,result,message}=res
          this.$hideLoading()
          if(code===200){
            this.$showToast(result)
            this.$navigateBack()
          } else {
            this.$showToast(message)
          }
        }).catch(e=>{
          this.$hideLoading()
          console.log ( e )
        })
      },
      onActiveTimeChange(e,key='start'){
        const moment = this.$moment()
        const { day, month, year,hour,minute,second } = e
        const time = `${year}-${month}-${day} ${hour}:${minute}:${second}`
        if (time < moment.format('YYYY-MM-DD')) {
          this.$showToast(`不能选择过期的时间,请重新选择`)
          return false
        }
        this.active[key].value = time
        this.active[key].appointmentDate = time
        const interviewTime = this.active[key].value
        this.timeValue = interviewTime
      },
      //预约开始
      onappActiveStartDataChange(e){
        this.onActiveTimeChange(e,'appointmentstart')
      },
      //设置时间操作
      getTimeDates(){
        const {ymd,startTime,endTime} =getTimeDate ()
        const active = this.active
        active.appointmentstart.appointmentDate = ymd
        active.appointmentstart.startTime = startTime
        active.appointmentstart.endTime = endTime
      },
      //公司下的职位信息-分页列表查询
      async companyPositionList(){
        await this.getCurrentPageList(companyPositionList,{pageNo:this.pageNo,
          pageSize:300,
          companyId:this.$store.state.userInfo.companyId
        })

      },
      onSelectTime(){
        this.active.appointmentstart.show=true
      }
    }
	}
</script>

<style lang="scss" scoped>
.invitelrview{
  background: #F9F9F9;
  height: 100vh;
  .abc{
    padding:16rpx 23rpx 0 30rpx;
    .h1{
      width: 229rpx;
      font-size: 32rpx;
      font-family: Adobe Heiti Std;
      font-weight: normal;
      color: #333333;
      line-height: 36rpx;
      margin-bottom: 35rpx;
      padding-top: 30rpx;
    }
    .pos{
      display: flex;
      flex-wrap: wrap;
      padding-bottom: 40rpx;
      .name{
        min-width: 181rpx;
        height: 54rpx;
        line-height: 54rpx;
        border: 1rpx solid #F39800;
        border-radius: 10rpx;
        text-align: center;
        margin-right: 26rpx;
        margin-bottom: 26rpx;
        font-size: 28rpx;
        &.active{
          background: #F39800;
          color: #fff;
        }
      }
    }
  }
  .abced{
    background: #fff;
  }
  .def{
    padding:16rpx 23rpx 0 30rpx;
  }
  /deep/ .u-cell_title{
    width: 179rpx;
    height: 29rpx;
    font-size: 31rpx;
    font-family: Adobe Heiti Std;
    font-weight: normal;
    color: #53B9B2;
    line-height: 29rpx;
  }
}
</style>
